//
//  EditAccount.m
//  MUBATE
//
//  Created by sunbin on 2017/2/20.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "EditAccount.h"

@implementation EditAccount

+ (void)editty:(editAccount)editType modifyMake:(modifyTy)modifyMake codeOperate:(codeOperate)operate editAccount:(NSString *)account scode:(NSString *)scode success:(void (^)(NSDictionary * successResults, NSString* successMsg))editSuccess
       failure:(void (^)(NSDictionary * failedResults, responseState resMake, NSString* failedMsg))editFailed{
    //接口API
    NSString *api = editType==editPhone?EDITPHONE:EDITEMAIL;
    
    NSDictionary *parameters;
    // 发送验证码 提交验证码 参数
    switch (operate) {
        case sendingCode:
            parameters = editType==editPhone?
            @{@"uid":@([YConfig getOwnID]),@"send":@(1),@"nphone":account ,@"sign":SIGN}:
            @{@"uid":@([YConfig getOwnID]),@"send":@(1),@"nemail":account ,@"sign":SIGN};
            break;
        case submitCode:
            parameters = editType==editPhone?
            @{@"uid":@([YConfig getOwnID]),@"scode":scode,@"nphone":account,@"sign":SIGN}:
            @{@"uid":@([YConfig getOwnID]),@"scode":scode,@"nemail":account,@"sign":SIGN};
            break;
            
        default:
            break;
    }
    
    
    //注释 当失败时无msg
    [ZL_NetworkHelper POST:api parameters:parameters success:^(id responseObject) {
        NSDictionary *dic = (NSDictionary *)responseObject;
        
        NSString *res = IF_NULL_TO_STRING([dic objectForKey:@"res"]);
        NSString *msg = IF_NULL_TO_STRING([dic objectForKey:@"msg"]);

        if ([res isEqualToString:@"1"]) {
            editSuccess(dic ,msg);
        }else{
            editFailed(nil , Error ,msg);
        }
    } failure:^(NSError *error) {
        NSLog(@"error.localizedDescription=%@" ,error.localizedDescription);
        editFailed(nil , Failure ,error.localizedDescription);
    }];
    

}


@end
